package com.chzc.fm.duotin.adapter.viewpager;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.chzc.fm.duotin.utils.ImageUtil;
import com.chzc.fm.duotin.utils.LogUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Liu Jianping
 *
 * @date : 16/6/8.
 */
public class CommImagePagerAdapter extends PagerAdapter {

    //显示图片的ImageView
    private List<ImageView> viewList;

    //图片的地址
    private List<String> urlList;

    public CommImagePagerAdapter(List<ImageView> viewList, List<String> urlList) {
        this.viewList = viewList;
        this.urlList = urlList;
    }

    @Override
    public int getCount() {

        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {

        LogUtil.w(">>>>>>>>>>>>>>>>>>>>>>>>>>>");

        ImageView imageView = viewList.get(position%viewList.size());
        container.addView(imageView);

        ImageLoader.getInstance().displayImage(urlList.get(position%viewList.size()),imageView, ImageUtil.getDefaultOptions());

        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ImageView imageView = viewList.get(position%viewList.size());
        container.removeView(imageView);
    }
}
